package ui.fragment.homepagefragment.doworkfragment;

import android.support.v4.app.Fragment;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;

import com.luck.picture.lib.PictureSelector;
import com.luck.picture.lib.entity.LocalMedia;

import java.util.ArrayList;
import java.util.List;

import base.BaseBean;
import base.fragment.BaseNetFragment;
import bean.ListOfPapersBean;
import student.andlei.com.student.R;
import ui.activity.DoTheImageWorkActivity;
import ui.fragment.minefragment.FeedbackFragment;
import utils.GlideUtils;

public class TestPaperFragment extends BaseNetFragment{
    private ImageView img_left,img_right;
    private ImageView img_content;
    private Button bt_annswer;
    private List<LocalMedia> selectList = new ArrayList<>();//图片集合
    private int i = 0;
    public static Fragment getInstance() {
        return new TestPaperFragment();
    }
    @Override
    public void success(String action, BaseBean baseBean) {

    }

    @Override
    public void error(String action, Throwable e) {

    }

    @Override
    protected int getLayoutId() {
        return R.layout.fragment_test_paper;
    }

    @Override
    protected void findViews() {
        img_content = getView(R.id.img_content);
        img_left = getView(R.id.img_left);
        img_right = getView(R.id.img_right);
        bt_annswer = getView(R.id.bt_answer);
    }

    @Override
    protected void formatViews() {
        img_content.setOnClickListener(this);
        img_left.setOnClickListener(this);
        img_right.setOnClickListener(this);
        bt_annswer.setOnClickListener(this);
    }

    @Override
    protected void formatData() {
        for(ListOfPapersBean.Paper_image paper_image: DoTheImageWorkActivity.paperimg_list){
            LocalMedia localMedia = new LocalMedia();
            localMedia.setPath(paper_image.paper_image);
            localMedia.setCompressPath(paper_image.paper_image);
            localMedia.setCutPath(paper_image.paper_image);
            selectList.add(localMedia);
        }
        GlideUtils.loadImageViewNoteLoding(context,selectList.get(i).getPath(),img_content);
    }

    @Override
    protected void getBundle() {

    }
    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.img_content:
                // 预览图片
                PictureSelector.create(TestPaperFragment.this).themeStyle(R.style.picture_default_style).openExternalPreview(i, selectList);
                break;
            case R.id.img_left:
                //上一张
                if(i<=0){
                    return;
                }
                i--;
                GlideUtils.loadImageViewNoteLoding(context,selectList.get(i).getPath(),img_content);
                break;
            case R.id.img_right:
                //下一张
                if(i>=selectList.size()-1){
                    return;
                }
                i++;
                GlideUtils.loadImageViewNoteLoding(context,selectList.get(i).getPath(),img_content);
                break;
            case R.id.bt_answer:
                //答题
                ((DoTheImageWorkActivity)getActivity()).jumpToDoTheImageWork();
                break;
        }
    }
}
